<?php

// +----------------------------------------------------------------------
// | UBTEN.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------
namespace User\Controller;
use Think\Controller;

class BaseController extends Controller {

    //put your code here

 public function _initialize() {

        $forward = getUrl();
        $loginUrl = USERS_URL . '/Login/index?forward=' . $forward;
        $this->loginUrl = $loginUrl;
        $this->assign('forward', $forward);
        $this->assign('loginUrl', $loginUrl);
        
        $ob = M("config");
        $config = $ob->field('name,data')->select();
        foreach ($config as $key => $value) {
            C($value['name'], $value['data']);
        }
        
        //未登录调转至登录页
        if(!session('user_id')){
            //记录跳转至登陆页面前的地址
            session("forward",$forward);
            $this->redirect('Login/index');
        }
        
        $all = M('Order')->where(array('user_id'=>session('user_id')))->count();
        $waitPay = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>10))->count();
        $waitSend = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>20))->count();
        $waitConfirm = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>30))->count();
        $waitRate = M('Order')->where(array('user_id'=>session('user_id'),'order_state'=>40))->count();
        $this->assign("all", $all);
        $this->assign("waitPay", $waitPay);
        $this->assign("waitSend", $waitSend);
        $this->assign("waitConfirm", $waitConfirm);
        $this->assign("waitRate", $waitRate);
        
    }


}
